package org.ccu.servlet;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ccu.dao.BuildingDAO;
import org.ccu.dao.SearchDAO;
import org.ccu.vo.Building;

/**
 * Servlet implementation class IniServlet
 */
public class IniServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public IniServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");

		String key = request.getParameter("engine");
		List<Building> s;
		if (key == null) {
			s = BuildingDAO.getBuilding();
			System.out.println("khfiah");
		} else {
			s = SearchDAO.getBuilding(key);
		}
		request.setAttribute("titles", s);
		

		request.getRequestDispatcher("/pages/main.jsp").forward(request,
				response);

	}

}
